* (bug 1107) Work around includes problem when parent dir is not readable
[lhc/web/wiklou.git] / config / index.php
1 <?php
2 # MediaWiki web-based config/installation
3 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
4 # http://www.mediawiki.org/
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # http://www.gnu.org/copyleft/gpl.html
20
21 error_reporting( E_ALL );
22 header( "Content-type: text/html; charset=utf-8" );
23 @ini_set( "display_errors", true );
24
25 ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
26 "http://www.w3.org/TR/html4/loose.dtd">
27 <html>
28 <head>
29 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
30 <meta name="robots" content="noindex,nofollow">
31 <title>MediaWiki installation</title>
32 <style type="text/css">
33 #credit {
34 float: right;
35 width: 200px;
36 font-size: 0.7em;
37 background-color: #eee;
38 color: black;
39 border: solid 1px #444;
40 padding: 8px;
41 margin-left: 8px;
42 }
43
44 dl.setup dd {
45 margin-left: 0;
46 }
47 dl.setup dd label.column {
48 clear: left;
49 font-weight: bold;
50 width: 12em;
51 float: left;
52 text-align: right;
53 padding-right: 1em;
54 }
55 dl.setup dt {
56 clear: left;
57 font-size: 0.8em;
58 margin-left: 10em;
59 /* margin-right: 200px; */
60 margin-bottom: 2em;
61 }
62 .error {
63 color: red;
64 }
65 ul.plain {
66 list-style: none;
67 clear: both;
68 margin-left: 12em;
69 }
70 </style>
71 </head>
72
73 <body>
74
75 <div id="credit">
76 <center>
77 <a href="http://www.mediawiki.org/">
78 <img src="../skins/common/images/mediawiki.png" width="135" height="135" alt="" border="0" />
79 </a>
80 </center>
81
82 <strong><a href="http://www.mediawiki.org/">MediaWiki</a></strong> is
83 Copyright (C) 2001-<?=date('Y')?> by Magnus Manske, Brion Vibber, Lee Daniel Crocker,
84 Tim Starling, Erik M&ouml;ller, Gabriel Wicke, Thomas Gries and others.</p>
85
86 <ul>
87 <li><a href="../README">Readme</a></li>
88 <li><a href="../RELEASE-NOTES">Release notes</a></li>
89 <li><a href="../docs/">doc/</a></li>
90 <li><a href="http://meta.wikipedia.org/wiki/MediaWiki_User's_Guide">User's Guide</a></li>
91 </ul>
92
93 <p>This program is free software; you can redistribute it and/or modify
94 it under the terms of the GNU General Public License as published by
95 the Free Software Foundation; either version 2 of the License, or
96 (at your option) any later version.</p>
97
98 <p>This program is distributed in the hope that it will be useful,
99 but WITHOUT ANY WARRANTY; without even the implied warranty of
100 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
101 GNU General Public License for more details.</p>
102
103 <p>You should have received <a href="../COPYING">a copy of the GNU General Public License</a>
104 along with this program; if not, write to the Free Software
105 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
106 or <a href="http://www.gnu.org/copyleft/gpl.html">read it online</a></p>
107 </div>
108
109 <?php
110
111 # Relative includes seem to break if a parent directory is not readable;
112 # this is common for public_html subdirs under user home directories.
113 #
114 # As a dirty hack, we'll try to set up the include path first.
115 #
116 $IP = dirname( dirname( __FILE__ ) );
117 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
118 ini_set( "include_path", ".$sep$IP$sep$IP/includes$sep$IP/languages" );
119
120 define( "MEDIAWIKI", true );
121 define( "MEDIAWIKI_INSTALL", true );
122 require_once( "includes/Defines.php" );
123 require_once( "includes/DefaultSettings.php" );
124 require_once( "includes/MagicWord.php" );
125 require_once( "includes/Namespace.php" );
126 ?>
127
128 <h1>MediaWiki <?php print $wgVersion ?> installation</h1>
129
130
131 <?php
132
133 /* Check for existing configurations and bug out! */
134
135 if( file_exists( "../LocalSettings.php" ) ) {
136 dieout( "<h2>Wiki is configured.</h2>
137
138 <p>Already configured... <a href='../index.php'>return to the wiki</a>.</p>
139
140 <p>(You should probably remove this directory for added security.)</p>" );
141 }
142
143 if( file_exists( "./LocalSettings.php" ) ) {
144 dieout( "<h2>You're configured!</h2>
145
146 <p>Please move <tt>LocalSettings.php</tt> to the parent directory, then
147 <a href='../index.php'>try out your wiki</a>.
148 (You should remove this config directory for added security once you're done.)</p>" );
149 }
150
151 if( !is_writable( "." ) ) {
152 dieout( "<h2>Can't write config file, aborting</h2>
153
154 <p>In order to configure the wiki you have to make the <tt>config</tt> subdirectory
155 writable by the web server. Once configuration is done you'll move the created
156 <tt>LocalSettings.php</tt> to the parent directory, and for added safety you can
157 then remove the <tt>config</tt> subdirectory entirely.</p>
158
159 <p>To make the directory writable on a Unix/Linux system:</p>
160
161 <blockquote>
162 <tt>cd /path/to/wiki</tt><br>
163 <tt>chmod a+w config</tt>
164 </blockquote>" );
165 }
166
167
168 require_once( "install-utils.inc" );
169 require_once( "maintenance/updaters.inc" );
170 require_once( "maintenance/convertLinks.inc" );
171 require_once( "maintenance/archives/moveCustomMessages.inc" );
172
173 class ConfigData {
174 function getEncoded( $data ) {
175 # removing latin1 support, no need...
176 return $data;
177 }
178 function getSitename() { return $this->getEncoded( $this->Sitename ); }
179 function getSysopName() { return $this->getEncoded( $this->SysopName ); }
180 function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
181 }
182
183 ?>
184
185 <p><em>Please include all of the lines below when reporting installation problems.</em></p>
186
187 <h2>Checking environment...</h2>
188 <ul>
189 <?php
190 $endl = "
191 ";
192 $wgNoOutputBuffer = true;
193 $conf = new ConfigData;
194
195 install_version_checks();
196
197 print "<li>PHP " . phpversion() . ": ok</li>\n";
198
199 if( ini_get( "register_globals" ) ) {
200 ?>
201 <li><b class='error'>Warning:</b> <strong>PHP's
202 <tt><a href="http://php.net/register_globals">register_globals</a></tt>
203 option is enabled.</strong> MediaWiki will work correctly, but this setting
204 increases your exposure to potential security vulnerabilities in PHP-based
205 software running on your server. <strong>You should disable it if you are able.</strong></li>
206 <?php
207 }
208
209 if( ini_get( "safe_mode" ) ) {
210 ?>
211 <li class='error'><strong>Warning: PHP's
212 <a href='http://www.php.net/features.safe-mode'>safe mode</a> is active!</strong>
213 You may have problems caused by this, particularly if using image uploads.
214 </li>
215 <?php
216 }
217
218 $fatal = false;
219
220 if( ini_get( "magic_quotes_runtime" ) ) {
221 $fatal = true;
222 ?><li class='error'><strong>Fatal: <a href='http://www.php.net/manual/en/ref.info.php#ini.magic-quotes-runtime'>magic_quotes_runtime</a> is active!</strong>
223 This option corrupts data input unpredictably; you cannot install or use
224 MediaWiki unless this option is disabled.
225 <?php
226 }
227
228 if( ini_get( "magic_quotes_sybase" ) ) {
229 $fatal = true;
230 ?><li class='error'><strong>Fatal: <a href='http://www.php.net/manual/en/ref.sybase.php#ini.magic-quotes-sybase'>magic_quotes_sybase</a> is active!</strong>
231 This option corrupts data input unpredictably; you cannot install or use
232 MediaWiki unless this option is disabled.
233 <?php
234 }
235
236 if( $fatal ) {
237 dieout( "</ul><p>Cannot install wiki.</p>" );
238 }
239
240 $sapi = php_sapi_name();
241 $conf->prettyURLs = true;
242 print "<li>PHP server API is $sapi; ";
243 switch( $sapi ) {
244 case "apache":
245 case "apache2handler":
246 print "ok, using pretty URLs (<tt>index.php/Page_Title</tt>)";
247 break;
248 case "cgi":
249 case "cgi-fcgi":
250 case "apache2filter":
251 print "using ugly URLs (<tt>index.php?title=Page_Title</tt>)";
252 $conf->prettyURLs = false;
253 break;
254 default:
255 print "unknown; using pretty URLs (<tt>index.php/Page_Title</tt>), if you have trouble change this in <tt>LocalSettings.php</tt>";
256 }
257 print "</li>\n";
258
259 $conf->xml = function_exists( "utf8_encode" );
260 if( $conf->xml ) {
261 print "<li>Have XML / Latin1-UTF-8 conversion support.</li>\n";
262 } else {
263 dieout( "PHP's XML module is missing; the wiki requires functions in
264 this module and won't work in this configuration.
265 If you're running Mandrake, install the php-xml package." );
266 }
267
268 $memlimit = ini_get( "memory_limit" );
269 $conf->raiseMemory = false;
270 if( empty( $memlimit ) ) {
271 print "<li>PHP is configured with no <tt>memory_limit</tt>.</li>\n";
272 } else {
273 print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ) . ". <strong>If this is too low, installation may fail!</strong> ";
274 $n = IntVal( $memlimit );
275 if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) {
276 $n = IntVal( $m[1] * (1024*1024) );
277 }
278 if( $n < 20*1024*1024 ) {
279 print "Attempting to raise limit to 20M... ";
280 if( false === ini_set( "memory_limit", "20M" ) ) {
281 print "failed.";
282 } else {
283 $conf->raiseMemory = true;
284 print "ok.";
285 }
286 }
287 print "</li>\n";
288 }
289
290 $conf->zlib = function_exists( "gzencode" );
291 if( $conf->zlib ) {
292 print "<li>Have zlib support; enabling output compression.</li>\n";
293 } else {
294 print "<li>No zlib support.</li>\n";
295 }
296
297 $conf->turck = function_exists( 'mmcache_get' );
298 if ( $conf->turck ) {
299 print "<li><a href=\"http://turck-mmcache.sourceforge.net/\">Turck MMCache</a> installed</li>\n";
300 }
301 $conf->eaccel = function_exists( 'eaccelerator_get' );
302 if ( $conf->eaccel ) {
303 $conf->turck = 'eaccelerator';
304 print "<li><a href=\"http://eaccelerator.sourceforge.net/\">eAccelerator</a> installed</li>\n";
305 }
306 if (!$conf->turck && !$conf->eaccel) {
307 print "<li>Neither <a href=\"http://turck-mmcache.sourceforge.net/\">Turck MMCache</a> nor <a href=\"http://eaccelerator.sourceforge.net/\">eAccelerator</a> are installed, " .
308 "can't use object caching functions</li>\n";
309 }
310
311 $conf->ImageMagick = false;
312 $imcheck = array( "/usr/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
313 foreach( $imcheck as $dir ) {
314 $im = "$dir/convert";
315 if( file_exists( $im ) ) {
316 print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
317 $conf->ImageMagick = $im;
318 break;
319 }
320 }
321
322 $conf->HaveGD = function_exists( "imagejpeg" );
323 if( $conf->HaveGD ) {
324 print "<li>Found GD graphics library built-in";
325 if( !$conf->ImageMagick ) {
326 print ", image thumbnailing will be enabled if you enable uploads";
327 }
328 print ".</li>\n";
329 } else {
330 if( !$conf->ImageMagick ) {
331 print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n";
332 }
333 }
334
335 $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;
336
337 # $conf->IP = "/Users/brion/Sites/inplace";
338 $conf->IP = dirname( dirname( __FILE__ ) );
339 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
340
341 # $conf->ScriptPath = "/~brion/inplace";
342 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $_SERVER["PHP_SELF"] ); # was SCRIPT_NAME
343 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
344
345 $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
346
347 $conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
348 $defaultEmail = empty( $_SERVER["SERVER_ADMIN"] )
349 ? 'root@localhost'
350 : $_SERVER["SERVER_ADMIN"];
351 $conf->EmergencyContact = importPost( "EmergencyContact", $defaultEmail );
352 $conf->DBserver = importPost( "DBserver", "localhost" );
353 $conf->DBname = importPost( "DBname", "wikidb" );
354 $conf->DBuser = importPost( "DBuser", "wikiuser" );
355 $conf->DBpassword = importPost( "DBpassword" );
356 $conf->DBpassword2 = importPost( "DBpassword2" );
357 $conf->DBprefix = importPost( "DBprefix" );
358 $conf->RootPW = importPost( "RootPW" );
359 $conf->LanguageCode = importPost( "LanguageCode", "en" );
360 $conf->SysopName = importPost( "SysopName", "WikiSysop" );
361 $conf->SysopPass = importPost( "SysopPass" );
362 $conf->SysopPass2 = importPost( "SysopPass2" );
363
364 /* Check for validity */
365 $errs = array();
366
367 if( $conf->Sitename == "" || $conf->Sitename == "MediaWiki" || $conf->Sitename == "Mediawiki" ) {
368 $errs["Sitename"] = "Must not be blank or \"MediaWiki\".";
369 }
370 if( $conf->DBuser == "" ) {
371 $errs["DBuser"] = "Must not be blank";
372 }
373 if( $conf->DBpassword == "" ) {
374 $errs["DBpassword"] = "Must not be blank";
375 }
376 if( $conf->DBpassword != $conf->DBpassword2 ) {
377 $errs["DBpassword2"] = "Passwords don't match!";
378 }
379 if( !preg_match( '/^[A-Za-z_0-9]*$/', $conf->DBprefix ) ) {
380 $errs["DBprefix"] = "Invalid table prefix";
381 }
382
383 if( $conf->SysopPass == "" ) {
384 $errs["SysopPass"] = "Must not be blank";
385 }
386 if( $conf->SysopPass != $conf->SysopPass2 ) {
387 $errs["SysopPass2"] = "Passwords don't match!";
388 }
389
390 $conf->License = importRequest( "License", "none" );
391 if( $conf->License == "gfdl" ) {
392 $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
393 $conf->RightsText = "GNU Free Documentation License 1.2";
394 $conf->RightsCode = "gfdl";
395 $conf->RightsIcon = '${wgStylePath}/common/images/gnu-fdl.png';
396 } elseif( $conf->License == "none" ) {
397 $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
398 } else {
399 $conf->RightsUrl = importRequest( "RightsUrl", "" );
400 $conf->RightsText = importRequest( "RightsText", "" );
401 $conf->RightsCode = importRequest( "RightsCode", "" );
402 $conf->RightsIcon = importRequest( "RightsIcon", "" );
403 }
404
405 $conf->Shm = importRequest( "Shm", "none" );
406 $conf->MCServers = importRequest( "MCServers" );
407
408 /* Test memcached servers */
409
410 if ( $conf->Shm == 'memcached' && $conf->MCServers ) {
411 $conf->MCServerArray = array_map( 'trim', explode( ',', $conf->MCServers ) );
412 foreach ( $conf->MCServerArray as $server ) {
413 $error = testMemcachedServer( $server );
414 if ( $error ) {
415 $errs["MCServers"] = $error;
416 break;
417 }
418 }
419 } else if ( $conf->Shm == 'memcached' ) {
420 $errs["MCServers"] = "Please specify at least one server if you wish to use memcached";
421 }
422
423 /* default values for installation */
424 $conf->Email =importRequest("Email", "email_enabled");
425 $conf->Emailuser=importRequest("Emailuser", "emailuser_enabled");
426 $conf->Enotif =importRequest("Enotif", "enotif_allpages");
427 $conf->Eauthent =importRequest("Eauthent", "eauthent_enabled");
428
429 if( $conf->posted && ( 0 == count( $errs ) ) ) {
430 do { /* So we can 'continue' to end prematurely */
431 $conf->Root = ($conf->RootPW != "");
432
433 /* Load up the settings and get installin' */
434 $local = writeLocalSettings( $conf );
435 $wgCommandLineMode = false;
436 chdir( ".." );
437 eval($local);
438 $wgDBadminuser = "root";
439 $wgDBadminpassword = $conf->RootPW;
440 $wgDBprefix = $conf->DBprefix;
441 $wgCommandLineMode = true;
442 $wgUseDatabaseMessages = false; /* FIXME: For database failure */
443 require_once( "includes/Setup.php" );
444 chdir( "config" );
445
446 require_once( "maintenance/InitialiseMessages.inc" );
447
448 $wgTitle = Title::newFromText( "Installation script" );
449 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 );
450 $wgDatabase->ignoreErrors(true);
451
452 @$myver = mysql_get_server_info( $wgDatabase->mConn );
453 if( $myver ) {
454 $conf->Root = true;
455 print "<li>Connected as root (automatic)</li>\n";
456 } else {
457 print "<li>MySQL error " . ($err = mysql_errno() ) .
458 ": " . htmlspecialchars( mysql_error() );
459 $ok = false;
460 switch( $err ) {
461 case 1045:
462 case 2000:
463 if( $conf->Root ) {
464 $errs["RootPW"] = "Check password";
465 } else {
466 print "<li>Trying regular user...\n";
467 /* Try the regular user... */
468 $wgDBadminuser = $wgDBuser;
469 $wgDBadminpassword = $wgDBpassword;
470 $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 );
471 $wgDatabase->isOpen();
472 $wgDatabase->ignoreErrors(true);
473 @$myver = mysql_get_server_info( $wgDatabase->mConn );
474 if( !$myver ) {
475 $errs["DBuser"] = "Check name/pass";
476 $errs["DBpassword"] = "or enter root";
477 $errs["DBpassword2"] = "password below";
478 $errs["RootPW"] = "Got root?";
479 print " need password.</li>\n";
480 } else {
481 $conf->Root = false;
482 $conf->RootPW = "";
483 print " ok.</li>\n";
484 # And keep going...
485 $ok = true;
486 }
487 break;
488 }
489 case 2002:
490 case 2003:
491 $errs["DBserver"] = "Connection failed";
492 break;
493 default:
494 $errs["DBserver"] = "Couldn't connect to database";
495 break;
496 }
497 if( !$ok ) continue;
498 }
499
500 if ( !$wgDatabase->isOpen() ) {
501 $errs["DBserver"] = "Couldn't connect to database";
502 continue;
503 }
504
505 print "<li>Connected to database... $myver";
506 if( version_compare( $myver, "4.0.0" ) >= 0 ) {
507 print "; enabling MySQL 4 enhancements";
508 $conf->DBmysql4 = true;
509 $local = writeLocalSettings( $conf );
510 }
511 print "</li>\n";
512
513 @$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
514 if( $sel ) {
515 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
516 } else {
517 $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
518 if( !$res ) {
519 print "<li>Couldn't create database <tt>" .
520 htmlspecialchars( $wgDBname ) .
521 "</tt>; try with root access or check your username/pass.</li>\n";
522 $errs["RootPW"] = "&lt;- Enter";
523 continue;
524 }
525 print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
526 }
527
528 $wgDatabase->selectDB( $wgDBname );
529
530 if( $wgDatabase->tableExists( "cur" ) || $wgDatabase->tableExists( "revision" ) ) {
531 print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n";
532
533 # Create user if required
534 if ( $conf->Root ) {
535 $conn = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
536 if ( $conn->isOpen() ) {
537 print "<li>DB user account ok</li>\n";
538 $conn->close();
539 } else {
540 print "<li>Granting user permissions...</li>\n";
541 dbsource( "../maintenance/users.sql", $wgDatabase );
542 }
543 }
544 print "<pre>\n";
545 chdir( ".." );
546 flush();
547 do_all_updates();
548 chdir( "config" );
549
550 print "</pre>\n";
551 print "<li>Finished update checks.</li>\n";
552 } else {
553 # FIXME: Check for errors
554 print "<li>Creating tables...";
555 dbsource( "../maintenance/tables.sql", $wgDatabase );
556 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
557 dbsource( "../maintenance/archives/patch-userlevels-defaultgroups.sql", $wgDatabase );
558 print " done.</li>\n";
559
560 print "<li>Initializing data...";
561 $wgDatabase->insert( 'site_stats',
562 array( 'ss_row_id' => 1,
563 'ss_total_views' => 0,
564 'ss_total_edits' => 0,
565 'ss_good_articles' => 0 ) );
566 # setting up the db user
567 if( $conf->Root ) {
568 print "<li>Granting user permissions...</li>\n";
569 dbsource( "../maintenance/users.sql", $wgDatabase );
570 }
571
572 if( $conf->SysopName ) {
573 $u = User::newFromName( $conf->getSysopName() );
574 if ( 0 == $u->idForName() ) {
575 $u->addToDatabase();
576 $u->setPassword( $conf->getSysopPass() );
577 $u->addRight( "sysop" );
578 $u->addRight( "bureaucrat" );
579 $u->saveSettings();
580
581 # Set up the new user in the sysop group
582 # This is a bit of an ugly hack
583 global $wgSysopGroupId, $wgBureaucratGroupId;
584 $groups = $u->getGroups();
585 $groups[] = $wgSysopGroupId;
586 $groups[] = $wgBureaucratGroupId;
587 $u->setGroups( $groups );
588 $u->saveSettings();
589
590 print "<li>Created sysop account <tt>" .
591 htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n";
592 } else {
593 print "<li>Could not create user - already exists!</li>\n";
594 }
595 } else {
596 print "<li>Skipped sysop account creation, no name given.</li>\n";
597 }
598
599 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
600 $article = new Article( $titleobj );
601 $newid = $article->insertOn( $wgDatabase );
602 $revision = new Revision( array(
603 'page' => $newid,
604 'text' => wfMsg( 'mainpagetext' ) . "\n\n" . wfMsg( 'mainpagedocfooter' ),
605 'comment' => '',
606 'user' => 0,
607 'user_text' => 'MediaWiki default',
608 ) );
609 $revid = $revision->insertOn( $wgDatabase );
610 $article->updateRevisionOn( $wgDatabase, $revision );
611
612 print "<li><pre>";
613 initialiseMessages();
614 print "</pre></li>\n";
615 }
616
617 /* Write out the config file now that all is well */
618 print "<p>Creating LocalSettings.php...</p>\n\n";
619 $localSettings = "<" . "?php$endl$local$endl?" . ">";
620 // Fix up a common line-ending problem (due to CVS on Windows)
621 $localSettings = str_replace( "\r\n", "\n", $localSettings );
622
623 if( version_compare( phpversion(), "4.3.2" ) >= 0 ) {
624 $xt = "xt"; # Refuse to overwrite an existing file
625 } else {
626 $xt = "wt"; # 'x' is not available prior to PHP 4.3.2. We did check above, but race conditions blah blah
627 }
628 $f = fopen( "LocalSettings.php", $xt );
629
630 if( $f == false ) {
631 dieout( "<p>Couldn't write out LocalSettings.php. Check that the directory permissions are correct and that there isn't already a file of that name here...</p>\n" .
632 "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" .
633 "<pre>\n" . htmlspecialchars( $localSettings ) . "</pre>\n" );
634 }
635 if(fwrite( $f, $localSettings ) ) {
636 fclose( $f );
637
638 print "<p>Success! Move the config/LocalSettings.php file into the parent directory, then follow
639 <a href='{$conf->ScriptPath}/index.php'>this link</a> to your wiki.</p>\n";
640 } else {
641 fclose( $f );
642 die("<p class='error'>An error occured while writing the config/LocalSettings.php file. Check user rights and disk space then try again.</p>\n");
643
644 }
645
646 } while( false );
647 }
648 ?>
649 </ul>
650
651
652 <?php
653
654 if( count( $errs ) ) {
655 /* Display options form */
656
657 if( $conf->posted ) {
658 echo "<p class='error'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
659 }
660 ?>
661
662 <form name="config" method="post">
663
664
665 <h2>Site config</h2>
666
667 <dl class="setup">
668 <dd>
669 <?php
670 aField( $conf, "Sitename", "Site name:" );
671 ?>
672 </dd>
673 <dt>
674 Your site name should be a relatively short word. It'll appear as the namespace
675 name for 'meta' pages as well as throughout the user interface. Good site names
676 are things like "<a href="http://www.wikipedia.org/">Wikipedia</a>" and
677 "<a href="http://openfacts.berlios.de/">OpenFacts</a>"; avoid punctuation,
678 which may cause problems.
679 </dt>
680
681 <dd>
682 <?php
683 aField( $conf, "EmergencyContact", "Contact e-mail" );
684 ?>
685 </dd>
686 <dt>
687 This will be used as the return address for password reminders and
688 may be displayed in some error conditions so visitors can get in
689 touch with you. It is also be used as the default sender address of e-mail
690 notifications (enotifs).
691 </dt>
692
693 <dd>
694 <label class='column' for="LanguageCode">Language</label>
695 <select id="LanguageCode" name="LanguageCode">
696
697 <?php
698 $list = getLanguageList();
699 foreach( $list as $code => $name ) {
700 $sel = ($code == $conf->LanguageCode) ? 'selected="selected"' : '';
701 echo "\t\t<option value=\"$code\" $sel>$name</option>\n";
702 }
703 ?>
704 </select>
705 </dd>
706 <dt>
707 You may select the language for the user interface of the wiki...
708 Some localizations are less complete than others. Unicode (UTF-8 encoding)
709 is used for all localizations.
710 </dt>
711
712 <dd>
713 <label class='column'>Copyright/license metadata</label>
714 <div>Select one:</div>
715
716 <ul class="plain">
717 <li><?php aField( $conf, "License", "no license metadata", "radio", "none" ); ?></li>
718 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.2 (Wikipedia-compatible)", "radio", "gfdl" ); ?></li>
719 <li><?php
720 aField( $conf, "License", "a Creative Commons license...", "radio", "cc" );
721 $partner = "MediaWiki";
722 $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/index.php?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
723 $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
724 $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
725 print "<a href=\"$ccApp\">choose</a>";
726 ?> (link will wipe out any other data in this form!)
727 <?php if( $conf->License == "cc" ) { ?>
728 <ul>
729 <li><?php aField( $conf, "RightsIcon", "<img src=\"" . htmlspecialchars( $conf->RightsIcon ) . "\" alt='icon' />", "hidden" ); ?></li>
730 <li><?php aField( $conf, "RightsText", htmlspecialchars( $conf->RightsText ), "hidden" ); ?></li>
731 <li><?php aField( $conf, "RightsCode", "code: " . htmlspecialchars( $conf->RightsCode ), "hidden" ); ?></li>
732 <li><?php aField( $conf, "RightsUrl", "<a href=\"" . htmlspecialchars( $conf->RightsUrl ) . "\">" . htmlspecialchars( $conf->RightsUrl ) . "</a>", "hidden" ); ?></li>
733 </ul>
734 <?php } ?>
735 </li>
736 </ul>
737 </dd>
738 <dt>
739 MediaWiki can include a basic license notice, icon, and machine-readable
740 copyright metadata if your wiki's content is to be licensed under
741 the GNU FDL or a Creative Commons license. If you're not sure, leave
742 it at "none".
743 </dt>
744
745
746 <dd>
747 <?php aField( $conf, "SysopName", "Sysop account name:", "" ) ?>
748 </dd>
749 <dd>
750 <?php aField( $conf, "SysopPass", "password:", "password" ) ?>
751 </dd>
752 <dd>
753 <?php aField( $conf, "SysopPass2", "again:", "password" ) ?>
754 </dd>
755 <dt>
756 A sysop user account can lock or delete pages, block problematic IP
757 addresses from editing, and other maintenance tasks. If creating a new
758 wiki database, a sysop account will be created with the given name
759 and password.
760 </dt>
761
762 <dd>
763 <label class='column'>Shared memory caching</label>
764 <div>Select one:</div>
765
766 <ul class="plain">
767 <li><?php aField( $conf, "Shm", "no caching", "radio", "none" ); ?></li>
768 <?php
769 if ( $conf->turck ) {
770 echo "<li>";
771 aField( $conf, "Shm", "Turck MMCache", "radio", "turck" );
772 echo "</li>";
773 }
774 ?>
775 <?php
776 if ( $conf->eaccel ) {
777 echo "<li>";
778 aField( $conf, "Shm", "eAccelerator", "radio", "eaccel" );
779 echo "</li>";
780 }
781 ?>
782 <li><?php aField( $conf, "Shm", "Memcached", "radio", "memcached" ); ?></li>
783 <li><?php aField( $conf, "MCServers", "Memcached servers", "" ) ?></li>
784 </ul>
785 </dd>
786 <dt>
787 Using a shared memory system such as Turck MMCache, eAccelerator, or Memcached will speed
788 up MediaWiki significantly. Memcached is the best solution but needs to be
789 installed. Specify the server addresses and ports in a comma-separted list. Only
790 use Turck shared memory if the wiki will be running on a single Apache server.
791 </dl>
792
793 <h2>E-mail, e-mail notification and authentification setup</h2>
794
795 <dl class="setup">
796 <dd>
797 <label class='column'>E-mail (general)</label>
798 <div>Select one:</div>
799
800 <ul class="plain">
801 <li><?php aField( $conf, "Email", "enabled", "radio", "email_enabled" ); ?></li>
802 <li><?php aField( $conf, "Email", "disabled", "radio", "email_disabled" ); ?></li>
803 </ul>
804 </dd>
805 <dt>
806 Use this to disable all e-mail functions (send a password reminder, user-to-user e-mail and e-mail notification),
807 if sending e-mails on your server doesn't work.
808 </dt>
809 <dd>
810 <label class='column'>User-to-user e-mail</label>
811 <div>Select one:</div>
812
813 <ul class="plain">
814 <li><?php aField( $conf, "Emailuser", "enabled", "radio", "emailuser_enabled" ); ?></li>
815 <li><?php aField( $conf, "Emailuser", "disabled", "radio", "emailuser_disabled" ); ?></li>
816 </ul>
817 </dd>
818 <dt>
819 Use this to disable only the user-to-user e-mail function (EmailUser).
820 </dt>
821 <dd>
822 <label class='column'>E-mail notification</label>
823 <div>Select one:</div>
824
825 <ul class="plain">
826 <li><?php aField( $conf, "Enotif", "disabled", "radio", "enotif_disabled" ); ?></li>
827 <li><?php aField( $conf, "Enotif", "enabled for changes of watch-listed and user_talk pages (recommended for small wikis; perhaps not suited for large wikis)", "radio", "enotif_allpages" ); ?></li>
828 <li><?php aField( $conf, "Enotif", "enabled for changes of user_talk pages only (suited for small and large wikis)", "radio", "enotif_usertalk" ); ?></li>
829 </ul>
830 </dd>
831 <dt>
832 <p><?php
833 $ccEnotif = htmlspecialchars( 'http://meta.wikipedia.org/Enotif' );
834 print "<a href=\"$ccEnotif\">E-mail notification</a>";
835 ?>
836 sends a notification e-mail to a user, when the user_talk page is changed
837 and/or when watch-listed pages are changed, depending on the above settings.
838 When testing this feature, be reminded, that obviously an e-mail address must be present in your preferences
839 and that your own changes never trigger notifications to be sent to yourself.</p>
840
841 <p>Users get corresponding options to select or deselect in their users' preferences.
842 The user options are not shown on the preference page, if e-mail notification is disabled.</p>
843
844 <p>There are additional options for fine tuning in /includes/DefaultSettings.php .</p>
845 </dt>
846
847 <dd>
848 <label class='column'>E-mail address authentication</label>
849 <div>Select one:</div>
850
851 <ul class="plain">
852 <li><?php aField( $conf, "Eauthent", "disabled", "radio", "eauthent_disabled" ); ?></li>
853 <li><?php aField( $conf, "Eauthent", "enabled", "radio", "eauthent_enabled" ); ?></li>
854 </ul>
855 </dd>
856 <dt>
857 <p><?php
858 $ccEauthent = htmlspecialchars( 'http://meta.wikipedia.org/Eauthent' );
859 print "<a href=\"$ccEnotif\">E-mail address authentication</a>";
860 ?>
861 uses a scheme to authenticate e-mail addresses of the users. The user who initially enters or who changes his/her stored e-mail address
862 gets a one-time temporary password mailed to that address. The user can use the original password as long as wanted, however, the stored e-mail address
863 is only authenticated at the moment when the user logs in with the one-time temporary password.<p>
864
865 <p>The e-mail address stays authenticated as long as the user does not change it; the time of authentication is indicated
866 on the user preference page.</p>
867
868 <p>If the option is enabled, only authenticated e-mail addresses can receive EmailUser mails and/or
869 e-mail notification mails.</p>
870 </dt>
871
872 </dl>
873
874 <h2>Database config</h2>
875
876 <dl class="setup">
877 <dd><?php
878 aField( $conf, "DBserver", "MySQL server" );
879 ?></dd>
880 <dt>
881 If your database server isn't on your web server, enter the name
882 or IP address here.
883 </dt>
884
885 <dd><?php
886 aField( $conf, "DBname", "Database name" );
887 ?></dd>
888 <dd><?php
889 aField( $conf, "DBuser", "DB username" );
890 ?></dd>
891 <dd><?php
892 aField( $conf, "DBpassword", "DB password", "password" );
893 ?></dd>
894 <dd><?php
895 aField( $conf, "DBpassword2", "again", "password" );
896 ?></dd>
897 <dt>
898 If you only have a single user account and database available,
899 enter those here. If you have database root access (see below)
900 you can specify new accounts/databases to be created.
901 </dt>
902
903 <dd><?php
904 aField( $conf, "DBprefix", "Database table prefix" );
905 ?></dd>
906 <dt>
907 <p>If you need to share one database between multiple wikis, or
908 MediaWiki and another web application, you may choose to
909 add a prefix to all the table names to avoid conflicts.</p>
910
911 <p>Avoid exotic characters; something like <tt>mw_</tt> is good.</p>
912 </dt>
913
914 <dd>
915 <?php
916 aField( $conf, "RootPW", "DB root password", "password" );
917 ?>
918 </dd>
919 <dt>
920 You will only need this if the database and/or user account
921 above don't already exist.
922 Do <em>not</em> type in your machine's root password! MySQL
923 has its own "root" user with a separate password. (It might
924 even be blank, depending on your configuration.)
925 </dt>
926
927 <dd>
928 <label class='column'>&nbsp;</label>
929 <input type="submit" value="Install!" />
930 </dd>
931 </dl>
932
933
934 </form>
935
936 <?php
937 }
938
939 /* -------------------------------------------------------------------------------------- */
940
941 function escapePhpString( $string ) {
942 return strtr( $string,
943 array(
944 "\n" => "\\n",
945 "\r" => "\\r",
946 "\t" => "\\t",
947 "\\" => "\\\\",
948 "\$" => "\\\$",
949 "\"" => "\\\""
950 ));
951 }
952
953 function writeLocalSettings( $conf ) {
954 $conf->DBmysql4 = @$conf->DBmysql4 ? 'true' : 'false';
955 $conf->UseImageResize = $conf->UseImageResize ? 'true' : 'false';
956 $conf->PasswordSender = $conf->EmergencyContact;
957 $zlib = ($conf->zlib ? "" : "# ");
958 $magic = ($conf->ImageMagick ? "" : "# ");
959 $convert = ($conf->ImageMagick ? $conf->ImageMagick : "/usr/bin/convert" );
960 $pretty = ($conf->prettyURLs ? "" : "# ");
961 $ugly = ($conf->prettyURLs ? "# " : "");
962 $rights = ($conf->RightsUrl) ? "" : "# ";
963
964 switch ( $conf->Shm ) {
965 case 'memcached':
966 $cacheType = 'CACHE_MEMCACHED';
967 $mcservers = var_export( $conf->MCServerArray, true );
968 break;
969 case 'turck':
970 case 'eaccel':
971 $cacheType = 'CACHE_ACCEL';
972 $mcservers = 'array()';
973 break;
974 default:
975 $cacheType = 'CACHE_NONE';
976 $mcservers = 'array()';
977 }
978
979 if ( $conf->Email == 'email_enabled' ) {
980 $enableemail = 'true';
981 $enableuseremail = ( $conf->Emailuser == 'emailuser_enabled' ) ? 'true' : 'false' ;
982 $eauthent = ( $conf->Eauthent == 'eauthent_enabled' ) ? 'true' : 'false' ;
983 switch ( $conf->Enotif ) {
984 case 'enotif_usertalk':
985 $enotifusertalk = 'true';
986 $enotifwatchlist = 'false';
987 break;
988 case 'enotif_allpages':
989 $enotifusertalk = 'true';
990 $enotifwatchlist = 'true';
991 break;
992 default:
993 $enotifusertalk = 'false';
994 $enotifwatchlist = 'false';
995 }
996 } else {
997 $enableuseremail = 'false';
998 $enableemail = 'false';
999 $eauthent = 'false';
1000 $enotifusertalk = 'false';
1001 $enotifwatchlist = 'false';
1002 }
1003
1004 $file = @fopen( "/dev/urandom", "r" );
1005 if ( $file ) {
1006 $secretKey = bin2hex( fread( $file, 32 ) );
1007 fclose( $file );
1008 } else {
1009 $secretKey = "";
1010 for ( $i=0; $i<8; $i++ ) {
1011 $secretKey .= dechex(mt_rand(0, 0x7fffffff));
1012 }
1013 print "<li>Warning: \$wgSecretKey key is insecure, generated with mt_rand(). Consider changing it manually.</li>\n";
1014 }
1015
1016 # Add slashes to strings for double quoting
1017 $slconf = array_map( "escapePhpString", get_object_vars( $conf ) );
1018 if( $conf->License == 'gfdl' ) {
1019 # Needs literal string interpolation for the current style path
1020 $slconf['RightsIcon'] = $conf->RightsIcon;
1021 }
1022
1023 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
1024 return "
1025 # This file was automatically generated by the MediaWiki installer.
1026 # If you make manual changes, please keep track in case you need to
1027 # recreate them later.
1028
1029 \$IP = \"{$slconf['IP']}\";
1030 ini_set( \"include_path\", \".$sep\$IP$sep\$IP/includes$sep\$IP/languages\" );
1031 require_once( \"includes/DefaultSettings.php\" );
1032
1033 # If PHP's memory limit is very low, some operations may fail.
1034 " . ($conf->raiseMemory ? '' : '# ' ) . "ini_set( 'memory_limit', '20M' );" . "
1035
1036 if ( \$wgCommandLineMode ) {
1037 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
1038 die( \"This script must be run from the command line\\n\" );
1039 }
1040 } elseif ( empty( \$wgConfiguring ) ) {
1041 ## Compress output if the browser supports it
1042 {$zlib}if( !ini_get( 'zlib.output_compression' ) ) @ob_start( 'ob_gzhandler' );
1043 }
1044
1045 \$wgSitename = \"{$slconf['Sitename']}\";
1046
1047 \$wgScriptPath = \"{$slconf['ScriptPath']}\";
1048 \$wgScript = \"\$wgScriptPath/index.php\";
1049 \$wgRedirectScript = \"\$wgScriptPath/redirect.php\";
1050
1051 ## If using PHP as a CGI module, use the ugly URLs
1052 {$pretty}\$wgArticlePath = \"\$wgScript/\$1\";
1053 {$ugly}\$wgArticlePath = \"\$wgScript?title=\$1\";
1054
1055 \$wgStylePath = \"\$wgScriptPath/skins\";
1056 \$wgStyleDirectory = \"\$IP/skins\";
1057 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
1058
1059 \$wgUploadPath = \"\$wgScriptPath/images\";
1060 \$wgUploadDirectory = \"\$IP/images\";
1061
1062 \$wgEnableEmail = $enableemail;
1063 \$wgEnableUserEmail = $enableuseremail;
1064
1065 \$wgEmergencyContact = \"{$slconf['EmergencyContact']}\";
1066 \$wgPasswordSender = \"{$slconf['PasswordSender']}\";
1067
1068 ## For a detailed description of the following switches see
1069 ## http://meta.wikimedia.org/Enotif and http://meta.wikimedia.org/Eauthent
1070 ## There are many more options for fine tuning available see
1071 ## /includes/DefaultSettings.php
1072 ## UPO means: this is also a user preference option
1073 \$wgEmailNotificationForUserTalkPages = $enotifusertalk; # UPO
1074 \$wgEmailNotificationForWatchlistPages = $enotifwatchlist; # UPO
1075 \$wgEmailAuthentication = $eauthent;
1076
1077 \$wgDBserver = \"{$slconf['DBserver']}\";
1078 \$wgDBname = \"{$slconf['DBname']}\";
1079 \$wgDBuser = \"{$slconf['DBuser']}\";
1080 \$wgDBpassword = \"{$slconf['DBpassword']}\";
1081 \$wgDBprefix = \"{$slconf['DBprefix']}\";
1082
1083 # If you're on MySQL 3.x, this next line must be FALSE:
1084 \$wgDBmysql4 = \$wgEnablePersistentLC = {$conf->DBmysql4};
1085
1086 ## Shared memory settings
1087 \$wgMainCacheType = $cacheType;
1088 \$wgMemCachedServers = $mcservers;
1089
1090 ## To enable image uploads, make sure the 'images' directory
1091 ## is writable, then uncomment this:
1092 # \$wgEnableUploads = true;
1093 \$wgUseImageResize = {$conf->UseImageResize};
1094 {$magic}\$wgUseImageMagick = true;
1095 {$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
1096
1097 ## If you have the appropriate support software installed
1098 ## you can enable inline LaTeX equations:
1099 # \$wgUseTeX = true;
1100 \$wgMathPath = \"{\$wgUploadPath}/math\";
1101 \$wgMathDirectory = \"{\$wgUploadDirectory}/math\";
1102 \$wgTmpDirectory = \"{\$wgUploadDirectory}/tmp\";
1103
1104 \$wgLocalInterwiki = \$wgSitename;
1105
1106 \$wgLanguageCode = \"{$slconf['LanguageCode']}\";
1107
1108 \$wgProxyKey = \"$secretKey\";
1109
1110 ## Default skin: you can change the default skin. Use the internal symbolic
1111 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
1112 # \$wgDefaultSkin = 'monobook';
1113
1114 ## For attaching licensing metadata to pages, and displaying an
1115 ## appropriate copyright notice / icon. GNU Free Documentation
1116 ## License and Creative Commons licenses are supported so far.
1117 {$rights}\$wgEnableCreativeCommonsRdf = true;
1118 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
1119 \$wgRightsUrl = \"{$slconf['RightsUrl']}\";
1120 \$wgRightsText = \"{$slconf['RightsText']}\";
1121 \$wgRightsIcon = \"{$slconf['RightsIcon']}\";
1122 # \$wgRightsCode = \"{$slconf['RightsCode']}\"; # Not yet used
1123 ";
1124 }
1125
1126 function dieout( $text ) {
1127 die( $text . "\n\n</body>\n</html>" );
1128 }
1129
1130 function importVar( &$var, $name, $default = "" ) {
1131 if( isset( $var[$name] ) ) {
1132 $retval = $var[$name];
1133 if ( get_magic_quotes_gpc() ) {
1134 $retval = stripslashes( $retval );
1135 }
1136 } else {
1137 $retval = $default;
1138 }
1139 return $retval;
1140 }
1141
1142 function importPost( $name, $default = "" ) {
1143 return importVar( $_POST, $name, $default );
1144 }
1145
1146 function importRequest( $name, $default = "" ) {
1147 return importVar( $_REQUEST, $name, $default );
1148 }
1149
1150 function aField( &$conf, $field, $text, $type = "", $value = "" ) {
1151 if( $type != "" ) {
1152 $xtype = "type=\"$type\"";
1153 } else {
1154 $xtype = "";
1155 }
1156
1157 if(!(isset($id)) or ($id == "") ) $id = $field;
1158 $nolabel = ($type == "radio") || ($type == "hidden");
1159 if( $nolabel ) {
1160 echo "\t\t<label>";
1161 } else {
1162 echo "\t\t<label class='column' for=\"$id\">$text</label>\n";
1163 }
1164
1165 if( $type == "radio" && $value == $conf->$field ) {
1166 $checked = "checked='checked'";
1167 } else {
1168 $checked = "";
1169 }
1170 echo "\t\t<input $xtype name=\"$field\" id=\"$id\" $checked value=\"";
1171 if( $type == "radio" ) {
1172 echo htmlspecialchars( $value );
1173 } else {
1174 echo htmlspecialchars( $conf->$field );
1175 }
1176 echo "\" />\n";
1177 if( $nolabel ) {
1178 echo " $text</label>\n";
1179 }
1180
1181 global $errs;
1182 if(isset($errs[$field])) echo "<span class='error'>" . $errs[$field] . "</span>\n";
1183 }
1184
1185 function getLanguageList() {
1186 global $wgLanguageNames;
1187 if( !isset( $wgLanguageNames ) ) {
1188 $wgContLanguageCode = "xxx";
1189 function wfLocalUrl( $x ) { return $x; }
1190 function wfLocalUrlE( $x ) { return $x; }
1191 require_once( "languages/Names.php" );
1192 }
1193
1194 $codes = array();
1195
1196 $d = opendir( "../languages" );
1197 while( false !== ($f = readdir( $d ) ) ) {
1198 if( preg_match( '/Language([A-Z][a-z_]+)\.php$/', $f, $m ) ) {
1199 $code = str_replace( '_', '-', strtolower( $m[1] ) );
1200 if( isset( $wgLanguageNames[$code] ) ) {
1201 $name = $code . ' - ' . $wgLanguageNames[$code];
1202 } else {
1203 $name = $code;
1204 }
1205 $codes[$code] = $name;
1206 }
1207 }
1208 closedir( $d );
1209 ksort( $codes );
1210 return $codes;
1211 }
1212
1213 # Test a memcached server
1214 function testMemcachedServer( $server ) {
1215 $hostport = explode(":", $server);
1216 $errstr = false;
1217 $fp = false;
1218 if ( !function_exists( 'fsockopen' ) ) {
1219 $errstr = "Can't connect to memcached, fsockopen() not present";
1220 }
1221 if ( !$errstr && count( $hostport ) != 2 ) {
1222 $errstr = 'Please specify host and port';
1223 var_dump( $hostport );
1224 }
1225 if ( !$errstr ) {
1226 list( $host, $port ) = $hostport;
1227 $errno = 0;
1228 $fsockerr = '';
1229
1230 $fp = @fsockopen( $host, $port, $errno, $fsockerr, 1.0 );
1231 if ( $fp === false ) {
1232 $errstr = "Cannot connect to memcached on $host:$port : $fsockerr";
1233 }
1234 }
1235 if ( !$errstr ) {
1236 $command = "version\r\n";
1237 $bytes = fwrite( $fp, $command );
1238 if ( $bytes != strlen( $command ) ) {
1239 $errstr = "Cannot write to memcached socket on $host:$port";
1240 }
1241 }
1242 if ( !$errstr ) {
1243 $expected = "VERSION ";
1244 $response = fread( $fp, strlen( $expected ) );
1245 if ( $response != $expected ) {
1246 $errstr = "Didn't get correct memcached response from $host:$port";
1247 }
1248 }
1249 if ( $fp ) {
1250 fclose( $fp );
1251 }
1252 if ( !$errstr ) {
1253 echo "<li>Connected to memcached on $host:$port successfully";
1254 }
1255 return $errstr;
1256 }
1257 ?>
1258
1259 </body>
1260 </html>